/***********09-15-新加tab*********** */
const util = require('../../utils/util.js');
const api = require('../../config/api.js');
var app = getApp();
Page({
  data: {
    detail:'',
    activeCategoryId: 1,
    jtdmvs: [],
    cgdmvs: [],
    regionId: 0,
    page: 1,
    limit: 30,
    showType: 2,
    contents:'https://tv.swlive.cn/article/index/zldx1'
  },

  onLoad: function (options) {
    /******************加载交通部门************** */
    var that = this;
    //that.getRegions();
    that.getDmvsjt();
    that.getDmvscg();


  },
  getDmvsjt: function () {
    var that = this;
    util.request(api.SchoolListByCgJt, {
      regionId: that.data.regionId,
      starRating: 0,
      type: that.data.showType,
      page: that.data.page,
      limit: that.data.limit,
      pid:2
    }).then(function (res) {
      if (res.errno === 0) {
        //console.log(JSON.stringify(res.data.list));
        that.setData({
          jtdmvs: res.data.list,
          totalPages: res.data.pages
        });
      }
    });
  },
  getDmvscg: function () {
    var that = this;
    util.request(api.SchoolListByCgJt, {
      regionId: that.data.regionId,
      starRating: 0,
      type: that.data.showType,
      page: that.data.page,
      limit: that.data.limit,
      pid:1
    }).then(function (res) {
      if (res.errno === 0) {
        //console.log(JSON.stringify(res.data.list));
        that.setData({
          cgdmvs: res.data.list,
          totalPages: res.data.pages
        });
      }
    });
  },
  copyText: function (e) {
    console.log(e)
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  },
  openSchool: function(){
    wx.navigateTo({
      url: '/pages/examSite/schoolCanera/caneralist'
    })
  },





  tabClick: function (e) {
    this.setData({
      //activeIndex: e.currentTarget.id
      activeCategoryId: e.currentTarget.id
    });
  },

  tobm: function (e) {
    /*var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name
    wx.navigateTo({
      url: '/pages/signup/add?jiaxiaoId=' + id + "&jiaxiaoName=" + name
    })*/
    var hasLogin = wx.getStorageSync("app.globalData.hasLogin");
    if (!hasLogin) {
      wx.navigateTo({
        url: '/pages/auth/login/login',
      })
    }else{
      wx.navigateTo({
        url: '/pages/signupV3/selectCarModel?schoolId='+this.data.schoolId+'&schoolName='+this.data.detail.name,
      })
    }
  },

  onShareAppMessage: function (res) {
  },
  onPullDownRefresh: function () {
  }
  ,
  //地图跳转
  fnMap: function (e) {
    var location = e.currentTarget.dataset.location;
  },
  toNav: function (e) {
    var latitude=e.currentTarget.dataset.latitude;
    var longitude=e.currentTarget.dataset.longitude;
    var name=e.currentTarget.dataset.name;
    var address=e.currentTarget.dataset.address;
    //console.log(latitude+"----"+longitude);

    wx.openLocation({//?使用微信内置地图查看位置。
      latitude: Number(latitude),//要去地点的纬度
      longitude: Number(longitude),///要去地点的经度-地址
      name: name,
      address: address
    })
  },
  toTheory:function(){
    wx.navigateTo({
      url: '/pages/examSite/theory/index',
    })
  },
  toSubjectTwo:function(){
    wx.navigateTo({
      url: '/pages/examSite/subjectTwo/index',
    })
  },
  toSubjectThree:function(){
    wx.navigateTo({
      url: '/pages/examSite/subjectThree/index',
    })
  }
})